package cn.xm.basic.controller;

import cn.xm.basic.dto.PhoneSmsDto;
import cn.xm.basic.service.VerifyCodeService;
import cn.xm.basic.util.AjaxResult;
import cn.xm.basic.util.FastdfsUtil;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取验证码
     * @param key
     * @return
     * @throws Exception
     */
    @GetMapping("/image/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String key) throws Exception {
        String resultObj = verifyCodeService.getImageCode(key);
        return AjaxResult.me().success(resultObj);
    }

    /**
     * 发送短信
     * @param dto
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult sendSmsCode(@RequestBody  PhoneSmsDto dto) {
        verifyCodeService.sendSmsCode(dto);
        return AjaxResult.me().success();
    }



}
